import sys
sys.path.append('../')
if '__file__' in globals():
    import os, sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import numpy as np
from common.util import preprocess
from common.util import create_co_matrix
from common.util import cos_similarity

text = 'You say goodbye and I say hello.'
corpus, word_to_id, id_to_word = preprocess(text)
vocab_size = len(word_to_id)

C = create_co_matrix(corpus, vocab_size, 1)
c0 = C[word_to_id['you']]
c1 = C[word_to_id['i']]
print('cos_similarity(c0, c1): ', cos_similarity(c0, c1))

def most_similar(query, word_to_id, id_to_word, word_matrix, top):
    """查询某个单词与其它单词的相似度"""
    if query not in word_to_id:
        print('%s is not found' % query)
        return
    print('\n[query] ', query)